package com.fengye.school.controller;


import com.fengye.school.model.school.Student;
import com.fengye.school.response.ResponsePageResult;
import com.fengye.school.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 学院控制器
 *
 * @author sky
 * @since 2021/4/22 7:37 上午
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/save")
    public Student save(@RequestBody Student student) {
        return studentService.save(student);
    }

    @GetMapping("/list")
    public List<Student> list() {
        return studentService.list();
    }

    @GetMapping("/list/select")
    public List<Student> listForSelect() {
        return studentService.list();
    }


    @GetMapping("/list/page")
    public ResponsePageResult<Student> listByPage(int page, int limit) {
        return studentService.listByPage(Math.max((page - 1), 0), limit);
    }

    @DeleteMapping("/delete/all")
    public void deleteAll(Long[] ids){
        Arrays.stream(ids).forEach(System.out::println);
        studentService.deleteAll(ids);
    }

    @DeleteMapping("/delete/id/{id}")
    public void deleteById(@PathVariable(name = "id", required = true)Long id){
        studentService.deleteById(id);
    }
}
